package com.kiven.file;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.Reader;

public class FileWrite {
	public static void main(String[] args) throws Exception {
		/*FileOutputStream fos  = new FileOutputStream("/home/liqingwen/aaaaaa.txt");
		fos.write("kiven you are a foole......".getBytes());
		fos.close();*/
		
		/*FileInputStream fis = new FileInputStream("/home/liqingwen/aaaaaa.txt");
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("/home/liqingwen/aaaaaa.txt")));*/

		//归并排序算法
		int[] a = {0,2,4,6,8,10};
		int[] b = {1,3,5,7,9,11};
		//归并后要保存的数组
		int[] temp = new int[a.length + b.length];
		
		int index=0;
		for(int i=0,j=0;i<a.length && j<b.length;){
			if(a[i] > b[j]) {
				temp[index++] = b[j];
				j++;
			}
			else if(a[i] < b[j]) {
				temp[index++] = a[i];
				i++;
			}
			else {
				//控制当数组中要比较的两个数相等时的情况
				temp[index++] = a[i];
				temp[index++] = b[j];
				i++;
				j++;
			}
		}
		
		System.out.println(temp.length);
		for(int i=0;i<temp.length;i++) {
			System.out.println(temp[i]);
		}
	}
}
